package im

import (
    "fmt"
	"dhfshop/controllers/base"
	"thirdpaysdk/api/chinaums"
	"dhfshop/domain/im"
	"dhfshop/models/isv"
	"github.com/astaxie/beego"
)

type ChinaUmsNotifyController struct {
	base.BaseController
}

func (this *ChinaUmsNotifyController) ChinaUmsNotify() {
	notifyData := this.Ctx.Input.RequestBody
	beego.Debug("ChinaUmsNotify notifyData:", string(notifyData))
	//
	mid := this.GetString("mid")
	message := string(notifyData)
	acPay, err := isv.GetAcPayParamsByMchId(mid)
	if err != nil {
	    beego.Debug("GetAcPayParamsByMchId:", err.Error())
		return
	}
	rspMap, err := chinaums.ChinaUmsNotify(message, acPay.Appkey)
	if err != nil {
	    beego.Debug("ChinaUmsNotify:", err.Error())
		return
	}
	reqMap := make(map[string]string)
	for k, v := range rspMap {
		reqMap[k] = fmt.Sprintf("%v", v)
	}
	reqMap["merchant_id"] = mid
	reqMap["LocalKind"] = "CHINAUMS_NOTIFY"
	reqMap["attach"] = reqMap["attachedData"]
	imlayer.PushMsgSvrIns.PushDao <- &reqMap
	this.Ctx.WriteString("SUCCESS")
	return
}
